<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>自制深度学习框架--构建自己的计算图 | kiloGrand</title><meta name="keywords" content="kuiper_infer"><meta name="author" content="kiloGrand"><meta name="copyright" content="kiloGrand"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="PNNX PyTorch Neural Network eXchange(PNNX)是PyTorch模型互操作性的开放标准.PNNX为PyTorch提供了一种开源的模型格式，它定义了与PyTorch相匹配的数据流图和运算操作。我们的框架在PNNX之上封装了一层更加易用和简单的计算图格式，PyTorch训练好一个模型之后，然后模型需要转换到PNNX格式，然后PNNX格式我们再去读取，形成计算图。">
<meta property="og:type" content="article">
<meta property="og:title" content="自制深度学习框架--构建自己的计算图">
<meta property="og:url" content="https://kilogrand.gitee.io/2023/03/17/kuiper_infer-L7/index.html">
<meta property="og:site_name" content="kiloGrand">
<meta property="og:description" content="PNNX PyTorch Neural Network eXchange(PNNX)是PyTorch模型互操作性的开放标准.PNNX为PyTorch提供了一种开源的模型格式，它定义了与PyTorch相匹配的数据流图和运算操作。我们的框架在PNNX之上封装了一层更加易用和简单的计算图格式，PyTorch训练好一个模型之后，然后模型需要转换到PNNX格式，然后PNNX格式我们再去读取，形成计算图。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://kilogrand.gitee.io/img/coding.jpg">
<meta property="article:published_time" content="2023-03-17T12:00:00.000Z">
<meta property="article:modified_time" content="2023-04-03T07:54:49.554Z">
<meta property="article:author" content="kiloGrand">
<meta property="article:tag" content="kuiper_infer">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://kilogrand.gitee.io/img/coding.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://kilogrand.gitee.io/2023/03/17/kuiper_infer-L7/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '自制深度学习框架--构建自己的计算图',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-03 15:54:49'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/profile.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">46</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/coding.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">kiloGrand</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">自制深度学习框架--构建自己的计算图</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-17T12:00:00.000Z" title="发表于 2023-03-17 20:00:00">2023-03-17</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-03T07:54:49.554Z" title="更新于 2023-04-03 15:54:49">2023-04-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>12分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="自制深度学习框架--构建自己的计算图"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="PNNX"><a href="#PNNX" class="headerlink" title="PNNX"></a>PNNX</h2><blockquote>
<p>PyTorch Neural Network eXchange(PNNX)是PyTorch模型互操作性的开放标准.<br><a target="_blank" rel="noopener" href="https://github.com/Tencent/ncnn/tree/master/tools/pnnx">PNNX</a>为PyTorch提供了一种开源的模型格式，它定义了与PyTorch相匹配的数据流图和运算操作。<br>我们的框架在PNNX之上<code>封装</code>了一层更加易用和简单的计算图格式，<br>PyTorch训练好一个模型之后，然后模型需要转换到PNNX格式，然后PNNX格式我们再去读取，形成计算图。</p>
</blockquote>
<h2 id="PNNX的格式定义"><a href="#PNNX的格式定义" class="headerlink" title="PNNX的格式定义"></a>PNNX的格式定义</h2><p><strong>Operator(操作符)</strong></p>
<ul>
<li>Inputs: std::vector<operand*>，输入操作数</li>
<li>Outputs: std::vector<operand*>，输出操作数</li>
<li>Type: std::string，运算符的类型</li>
<li>Name: std::string，运算符的名称</li>
<li>Params: std::map，存放运算符的所有参数，例如卷积运算的stride, padding, kernel size</li>
<li>Attrs: std::map，存放运算符所需的具体权重属性，例如卷积的权重w和偏移量b</li>
</ul>
<p><strong>Operand(操作数)</strong></p>
<ul>
<li>Producer: operator，产生这个操作数的运算符，表示运算符的输出，只能有一个生产者</li>
<li>Customer: operator，下一个操作需要该操作数作为输入的运算符，表示运算符的输入，可以有多个消费者</li>
<li>Name: std::string，操作数的名称</li>
<li>shape: std::vector<int>，操作数的维度</li>
</ul>
<h2 id="定义我们自己的Operator和Operand"><a href="#定义我们自己的Operator和Operand" class="headerlink" title="定义我们自己的Operator和Operand"></a>定义我们自己的Operator和Operand</h2><p>我们给自己的神经网络推理框架定义了RuntimeOperator和RuntimeOperand</p>
<p><strong>RuntimeOperand</strong><br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeOperand</span> &#123;</span><br><span class="line">  std::string name;                      <span class="comment">// 操作数的名称</span></span><br><span class="line">  std::vector&lt;<span class="type">int32_t</span>&gt; shapes;   <span class="comment">// 操作数的形状</span></span><br><span class="line">  std::vector&lt;std::shared_ptr&lt;Tensor&lt;<span class="type">float</span>&gt;&gt;&gt; datas;                <span class="comment">// 存储操作数</span></span><br><span class="line">  RuntimeDataType type = RuntimeDataType::kTypeUnknown;  <span class="comment">// 操作数的类型，一般是float</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p><strong>RuntimeOperator</strong><br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeOperator</span> &#123;</span><br><span class="line">  <span class="type">int32_t</span> meet_num = <span class="number">0</span>; <span class="comment">// 计算节点被相连接节点访问到的次数</span></span><br><span class="line"></span><br><span class="line">  ~<span class="built_in">RuntimeOperator</span>() &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;param : <span class="keyword">this</span>-&gt;params) &#123;</span><br><span class="line">      <span class="keyword">delete</span> param.second;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  std::string name;                         <span class="comment">// 计算节点的名称</span></span><br><span class="line">  std::string type;                          <span class="comment">// 计算节点的类型</span></span><br><span class="line">  std::shared_ptr&lt;Layer&gt; layer;   <span class="comment">// 计算节点对应的计算Layer</span></span><br><span class="line"></span><br><span class="line">  std::vector&lt;std::string&gt; output_names;                          <span class="comment">// 节点的输出节点名称</span></span><br><span class="line">  std::shared_ptr&lt;RuntimeOperand&gt; output_operands;  <span class="comment">// 节点的输出操作数</span></span><br><span class="line"></span><br><span class="line">  std::map&lt;std::string, std::shared_ptr&lt;RuntimeOperand&gt;&gt; input_operands;     <span class="comment">// 节点的输入操作数</span></span><br><span class="line">  std::vector&lt;std::shared_ptr&lt;RuntimeOperand&gt;&gt; input_operands_seq;            <span class="comment">// 节点的输入操作数，顺序排列</span></span><br><span class="line">  std::map&lt;std::string, std::shared_ptr&lt;RuntimeOperator&gt;&gt; output_operators; <span class="comment">// 输出节点的名字和节点对应</span></span><br><span class="line"></span><br><span class="line">  std::map&lt;std::string, RuntimeParameter *&gt; params;                              <span class="comment">// 算子的参数信息</span></span><br><span class="line">  std::map&lt;std::string, std::shared_ptr&lt;RuntimeAttribute&gt; &gt; attribute;  <span class="comment">// 算子的属性信息，内含权重信息</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p>同时定义了一些类型的状态<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">enum class</span> <span class="title class_">RuntimeParameterType</span> &#123;</span><br><span class="line">  kParameterUnknown = <span class="number">0</span>,</span><br><span class="line">  kParameterBool = <span class="number">1</span>,</span><br><span class="line">  kParameterInt = <span class="number">2</span>,</span><br><span class="line"></span><br><span class="line">  kParameterFloat = <span class="number">3</span>,</span><br><span class="line">  kParameterString = <span class="number">4</span>,</span><br><span class="line">  kParameterIntArray = <span class="number">5</span>,</span><br><span class="line">  kParameterFloatArray = <span class="number">6</span>,</span><br><span class="line">  kParameterStringArray = <span class="number">7</span>,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">enum class</span> <span class="title class_">InferStatus</span> &#123;</span><br><span class="line">  kInferUnknown = <span class="number">-1</span>,</span><br><span class="line">  kInferFailedInputEmpty = <span class="number">1</span>,</span><br><span class="line">  kInferFailedWeightParameterError = <span class="number">2</span>,</span><br><span class="line">  kInferFailedBiasParameterError = <span class="number">3</span>,</span><br><span class="line">  kInferFailedStrideParameterError = <span class="number">4</span>,</span><br><span class="line">  kInferFailedDimensionParameterError = <span class="number">5</span>,</span><br><span class="line">  kInferFailedChannelParameterError = <span class="number">6</span>,</span><br><span class="line">  kInferFailedInputOutSizeAdaptingError = <span class="number">6</span>,</span><br><span class="line"></span><br><span class="line">  kInferFailedOutputSizeError = <span class="number">7</span>,</span><br><span class="line">  kInferFailedOperationUnknown = <span class="number">8</span>,</span><br><span class="line">  kInferFailedYoloStageNumberError = <span class="number">9</span>,</span><br><span class="line"></span><br><span class="line">  kInferSuccess = <span class="number">0</span>,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">enum class</span> <span class="title class_">ParseParameterAttrStatus</span> &#123;</span><br><span class="line">  kParameterMissingUnknown = <span class="number">-1</span>,</span><br><span class="line">  kParameterMissingStride = <span class="number">1</span>,</span><br><span class="line">  kParameterMissingPadding = <span class="number">2</span>,</span><br><span class="line">  kParameterMissingKernel = <span class="number">3</span>,</span><br><span class="line">  kParameterMissingUseBias = <span class="number">4</span>,</span><br><span class="line">  kParameterMissingInChannel = <span class="number">5</span>,</span><br><span class="line">  kParameterMissingOutChannel = <span class="number">6</span>,</span><br><span class="line"></span><br><span class="line">  kParameterMissingEps = <span class="number">7</span>,</span><br><span class="line">  kParameterMissingNumFeatures = <span class="number">8</span>,</span><br><span class="line">  kParameterMissingDim = <span class="number">9</span>,</span><br><span class="line">  kParameterMissingExpr = <span class="number">10</span>,</span><br><span class="line">  kParameterMissingOutHW = <span class="number">11</span>,</span><br><span class="line">  kParameterMissingShape = <span class="number">12</span>,</span><br><span class="line">  kParameterMissingGroups = <span class="number">13</span>,</span><br><span class="line">  kParameterMissingScale = <span class="number">14</span>,</span><br><span class="line">  kParameterMissingResizeMode = <span class="number">15</span>,</span><br><span class="line"></span><br><span class="line">  kAttrMissingBias = <span class="number">21</span>,</span><br><span class="line">  kAttrMissingWeight = <span class="number">22</span>,</span><br><span class="line">  kAttrMissingRunningMean = <span class="number">23</span>,</span><br><span class="line">  kAttrMissingRunningVar = <span class="number">24</span>,</span><br><span class="line">  kAttrMissingOutFeatures = <span class="number">25</span>,</span><br><span class="line">  kAttrMissingYoloStrides = <span class="number">26</span>,</span><br><span class="line">  kAttrMissingYoloAnchorGrides = <span class="number">27</span>,</span><br><span class="line">  kAttrMissingYoloGrides = <span class="number">28</span>,</span><br><span class="line"></span><br><span class="line">  kParameterAttrParseSuccess = <span class="number">0</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p>定义了一些参数<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameter</span> &#123; <span class="comment">// 计算节点中的参数信息 基类</span></span><br><span class="line">  <span class="keyword">virtual</span> ~<span class="built_in">RuntimeParameter</span>() = <span class="keyword">default</span>;</span><br><span class="line"></span><br><span class="line">  <span class="function"><span class="keyword">explicit</span> <span class="title">RuntimeParameter</span><span class="params">(RuntimeParameterType type = RuntimeParameterType::kParameterUnknown)</span> : type(type) &#123;</span></span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  RuntimeParameterType type = RuntimeParameterType::kParameterUnknown;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterInt</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterInt</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterInt) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="type">int</span> value = <span class="number">0</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterFloat</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterFloat</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterFloat) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="type">float</span> value = <span class="number">0.f</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterString</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterString</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterString) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  std::string value;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterIntArray</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterIntArray</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterIntArray) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  std::vector&lt;<span class="type">int</span>&gt; value;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterFloatArray</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterFloatArray</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterFloatArray) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  std::vector&lt;<span class="type">float</span>&gt; value;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterStringArray</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterStringArray</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterStringArray) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  std::vector&lt;std::string&gt; value;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">RuntimeParameterBool</span> : <span class="keyword">public</span> RuntimeParameter &#123;</span><br><span class="line">  <span class="built_in">RuntimeParameterBool</span>() : <span class="built_in">RuntimeParameter</span>(RuntimeParameterType::kParameterBool) &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="type">bool</span> value = <span class="literal">false</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p>最终，定义我们的计算图<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">RuntimeGraph</span> &#123;</span><br><span class="line"> <span class="keyword">public</span>:</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 计算图的初始化</span></span><br><span class="line"><span class="comment">   * @return 是否初始化成功</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">bool</span> <span class="title">Init</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 初始化计算图</span></span><br><span class="line"><span class="comment">   * @param param_path 计算图的结构文件</span></span><br><span class="line"><span class="comment">   * @param bin_path 计算图中的权重文件</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="built_in">RuntimeGraph</span>(std::string param_path, std::string bin_path);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 设置权重文件</span></span><br><span class="line"><span class="comment">   * @param bin_path 权重文件路径</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">void</span> <span class="title">set_bin_path</span><span class="params">(<span class="type">const</span> std::string &amp;bin_path)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 设置结构文件</span></span><br><span class="line"><span class="comment">   * @param param_path  结构文件路径</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">void</span> <span class="title">set_param_path</span><span class="params">(<span class="type">const</span> std::string &amp;param_path)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 返回结构文件</span></span><br><span class="line"><span class="comment">   * @return 返回结构文件</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">const</span> std::string &amp;<span class="title">param_path</span><span class="params">()</span> <span class="type">const</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 返回权重文件</span></span><br><span class="line"><span class="comment">   * @return 返回权重文件</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">const</span> std::string &amp;<span class="title">bin_path</span><span class="params">()</span> <span class="type">const</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="type">const</span> std::vector&lt;std::shared_ptr&lt;RuntimeOperator&gt;&gt; <span class="built_in">operators</span>() <span class="type">const</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span>:</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 初始化kuiper infer计算图节点中的输入操作数</span></span><br><span class="line"><span class="comment">   * @param inputs pnnx中的输入操作数</span></span><br><span class="line"><span class="comment">   * @param runtime_operator 计算图节点</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">static</span> <span class="type">void</span> <span class="title">InitInputOperators</span><span class="params">(<span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;inputs,</span></span></span><br><span class="line"><span class="params"><span class="function">                                 <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 初始化kuiper infer计算图节点中的输出操作数</span></span><br><span class="line"><span class="comment">   * @param outputs pnnx中的输出操作数</span></span><br><span class="line"><span class="comment">   * @param runtime_operator 计算图节点</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">static</span> <span class="type">void</span> <span class="title">InitOutputOperators</span><span class="params">(<span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;outputs,</span></span></span><br><span class="line"><span class="params"><span class="function">                                  <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 初始化kuiper infer计算图中的节点属性</span></span><br><span class="line"><span class="comment">   * @param attrs pnnx中的节点属性</span></span><br><span class="line"><span class="comment">   * @param runtime_operator 计算图节点</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">static</span> <span class="type">void</span> <span class="title">InitGraphAttrs</span><span class="params">(<span class="type">const</span> std::map&lt;std::string, pnnx::Attribute&gt; &amp;attrs,</span></span></span><br><span class="line"><span class="params"><span class="function">                             <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 初始化kuiper infer计算图中的节点参数</span></span><br><span class="line"><span class="comment">   * @param params pnnx中的参数属性</span></span><br><span class="line"><span class="comment">   * @param runtime_operator 计算图节点</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="type">static</span> <span class="type">void</span> <span class="title">InitGraphParams</span><span class="params">(<span class="type">const</span> std::map&lt;std::string, pnnx::Parameter&gt; &amp;params,</span></span></span><br><span class="line"><span class="params"><span class="function">                              <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span></span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span>:</span><br><span class="line">  <span class="keyword">enum class</span> <span class="title class_">GraphState</span> &#123;</span><br><span class="line">    NeedInit = <span class="number">-2</span>,</span><br><span class="line">    NeedBuild = <span class="number">-1</span>,</span><br><span class="line">    Complete = <span class="number">0</span>,</span><br><span class="line">  &#125;;</span><br><span class="line">  GraphState graph_state_ = GraphState::NeedInit;</span><br><span class="line">  std::string input_name_;    <span class="comment">// 计算图输入节点的名称</span></span><br><span class="line">  std::string output_name_; <span class="comment">// 计算图输出节点的名称</span></span><br><span class="line">  std::string param_path_;   <span class="comment">// 计算图的结构文件</span></span><br><span class="line">  std::string bin_path_;        <span class="comment">// 计算图的权重文件</span></span><br><span class="line">  std::map&lt;std::string, std::shared_ptr&lt;RuntimeOperator&gt;&gt; input_operators_maps_;    <span class="comment">// 保存输入节点</span></span><br><span class="line">  std::map&lt;std::string, std::shared_ptr&lt;RuntimeOperator&gt;&gt; output_operators_maps_; <span class="comment">// 保存输出节点</span></span><br><span class="line">  std::vector&lt;std::shared_ptr&lt;RuntimeOperator&gt;&gt; operators_;  <span class="comment">// 计算图的计算节点</span></span><br><span class="line">  std::unique_ptr&lt;pnnx::Graph&gt; graph_;                                      <span class="comment">// pnnx的graph</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<h2 id="从PNNX计算图到KuiperInfer计算图的过程"><a href="#从PNNX计算图到KuiperInfer计算图的过程" class="headerlink" title="从PNNX计算图到KuiperInfer计算图的过程"></a>从PNNX计算图到KuiperInfer计算图的过程</h2><ol>
<li><p>加载PNNX的计算图</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>-&gt;graph_ = std::<span class="built_in">make_unique</span>&lt;pnnx::Graph&gt;();</span><br><span class="line"><span class="type">int</span> load_result = <span class="keyword">this</span>-&gt;graph_-&gt;<span class="built_in">load</span>(param_path_, bin_path_);</span><br></pre></td></tr></table></figure>
</li>
<li><p>获取PNNX计算图中的运算符</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">std::vector&lt;pnnx::Operator *&gt; operators = <span class="keyword">this</span>-&gt;graph_-&gt;ops;</span><br></pre></td></tr></table></figure>
</li>
<li><p>遍历PNNX计算图中的运算符，构建我们的计算图</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 根据const pnnx::Operator *op 去赋值std::shared_ptr&lt;RuntimeOperator&gt; runtime_operator</span></span><br><span class="line"><span class="keyword">for</span> (<span class="type">const</span> pnnx::Operator *op : operators) &#123;</span><br><span class="line">  <span class="keyword">if</span> (!op) &#123;  <span class="comment">// 空的计算节点</span></span><br><span class="line">    <span class="built_in">LOG</span>(ERROR) &lt;&lt; <span class="string">&quot;Meet the empty node&quot;</span>;</span><br><span class="line">    <span class="keyword">continue</span>;</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    std::shared_ptr&lt;RuntimeOperator&gt; runtime_operator = std::<span class="built_in">make_shared</span>&lt;RuntimeOperator&gt;();</span><br><span class="line">    <span class="comment">// 初始化算子的名称</span></span><br><span class="line">    runtime_operator-&gt;name = op-&gt;name;</span><br><span class="line">    runtime_operator-&gt;type = op-&gt;type;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 初始化算子中的input，对操作符号operator赋予runtimeoperand作为输入，输入是根据pnnx::operand来的</span></span><br><span class="line">    <span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;inputs = op-&gt;inputs;</span><br><span class="line">    <span class="keyword">if</span> (!inputs.<span class="built_in">empty</span>()) &#123;</span><br><span class="line">      <span class="built_in">InitInputOperators</span>(inputs, runtime_operator);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 记录输出operand中的名称</span></span><br><span class="line">    <span class="comment">// 有一个pnnx::operator 来自与load_graph这个操作</span></span><br><span class="line">    <span class="comment">// load_graph pnnx::operators数组 进行遍历 pnnx::operator</span></span><br><span class="line">    <span class="comment">// 每一个遍历中operator，我们再初始化自己的kuiperinfer::RuntimeOperator</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/// RuntimeOperator根据pnnx::operator赋予inputs和outputs</span></span><br><span class="line">    <span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;outputs = op-&gt;outputs;</span><br><span class="line">    <span class="keyword">if</span> (!outputs.<span class="built_in">empty</span>()) &#123;</span><br><span class="line">      <span class="built_in">InitOutputOperators</span>(outputs, runtime_operator);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 初始化算子中的attribute(权重)</span></span><br><span class="line">    <span class="comment">//没一个pnnx::operator里面有一个权重，我们根据pnnx::Attr这个权重去初始化RuntimeAttr</span></span><br><span class="line">    <span class="comment">/// 初始化RutimeAttr之后呢，存放在runtime_operator</span></span><br><span class="line">    <span class="type">const</span> std::map&lt;std::string, pnnx::Attribute&gt; &amp;attrs = op-&gt;attrs;</span><br><span class="line">    <span class="keyword">if</span> (!attrs.<span class="built_in">empty</span>()) &#123;</span><br><span class="line">      <span class="built_in">InitGraphAttrs</span>(attrs, runtime_operator);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 初始化算子中的parameter</span></span><br><span class="line">    <span class="comment">// 根据const pnnx::Operator *op 去赋值std::shared_ptr&lt;RuntimeOperator&gt; runtime_operator</span></span><br><span class="line">    <span class="comment">// 先得到pnnx::parameter再根据这个去赋值RuntimeOperator中的RuntimeParameter</span></span><br><span class="line">    <span class="type">const</span> std::map&lt;std::string, pnnx::Parameter&gt; &amp;params = op-&gt;params;</span><br><span class="line">    <span class="keyword">if</span> (!params.<span class="built_in">empty</span>()) &#123;</span><br><span class="line">      <span class="built_in">InitGraphParams</span>(params, runtime_operator);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// runtime_operator初始化玩成了，存放到一个vector中</span></span><br><span class="line">    <span class="keyword">this</span>-&gt;operators_.<span class="built_in">push_back</span>(runtime_operator);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><strong>初始化RuntimeOperator的输入</strong><br>初始化RuntimeOperator中的RuntimeOperator.input_operands和RuntimeOperator.input_operands_seq两个属性。<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">RuntimeGraph::InitInputOperators</span><span class="params">(<span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;inputs,</span></span></span><br><span class="line"><span class="params"><span class="function">                                      <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span> </span>&#123;</span><br><span class="line">  <span class="comment">// 遍历PNNX的操作数operands</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="type">const</span> pnnx::Operand *input : inputs) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!input) &#123;</span><br><span class="line">      <span class="keyword">continue</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 得到pnnx操作数对应的生产者</span></span><br><span class="line">    <span class="type">const</span> pnnx::Operator *producer = input-&gt;producer;</span><br><span class="line">    <span class="comment">// 初始化runtime_operand</span></span><br><span class="line">    std::shared_ptr&lt;RuntimeOperand&gt; runtime_operand = std::<span class="built_in">make_shared</span>&lt;RuntimeOperand&gt;();</span><br><span class="line">    runtime_operand-&gt;name = producer-&gt;name;  <span class="comment">// 名称</span></span><br><span class="line">    runtime_operand-&gt;shapes = input-&gt;shape;      <span class="comment">// 形状 </span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">switch</span> (input-&gt;type) &#123;  <span class="comment">// 类型</span></span><br><span class="line">      <span class="keyword">case</span> <span class="number">1</span>: &#123;</span><br><span class="line">        runtime_operand-&gt;type = RuntimeDataType::kTypeFloat32;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">case</span> <span class="number">0</span>: &#123;</span><br><span class="line">        runtime_operand-&gt;type = RuntimeDataType::kTypeUnknown;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">default</span>: &#123;</span><br><span class="line">        <span class="built_in">LOG</span>(FATAL) &lt;&lt; <span class="string">&quot;Unknown input operand type: &quot;</span> &lt;&lt; input-&gt;type;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// runtime_operand放入到KuiperInfer的运算符中</span></span><br><span class="line">    runtime_operator-&gt;input_operands.<span class="built_in">insert</span>(&#123;producer-&gt;name, runtime_operand&#125;);</span><br><span class="line">    runtime_operator-&gt;input_operands_seq.<span class="built_in">push_back</span>(runtime_operand);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><strong>初始化RuntimeOperator中的输出</strong><br>初始化RuntimeOperator.output_names属性<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">RuntimeGraph::InitOutputOperators</span><span class="params">(<span class="type">const</span> std::vector&lt;pnnx::Operand *&gt; &amp;outputs,</span></span></span><br><span class="line"><span class="params"><span class="function">                                       <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span> </span>&#123;</span><br><span class="line">  <span class="comment">// 遍历pnnx操作数operands</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="type">const</span> pnnx::Operand *output : outputs) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!output) &#123; <span class="comment">// 空的操作数</span></span><br><span class="line">      <span class="keyword">continue</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 得到pnnx操作数对应的消费者</span></span><br><span class="line">    <span class="type">const</span> <span class="keyword">auto</span> &amp;consumers = output-&gt;consumers;</span><br><span class="line">    <span class="comment">// 初始化RuntimeOperator.output_names属性</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : consumers) &#123;</span><br><span class="line">      runtime_operator-&gt;output_names.<span class="built_in">push_back</span>(c-&gt;name);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><strong>初始化RuntimeOperator的权重(Attr)属性</strong><br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">RuntimeGraph::InitGraphAttrs</span><span class="params">(<span class="type">const</span> std::map&lt;std::string, pnnx::Attribute&gt; &amp;attrs,</span></span></span><br><span class="line"><span class="params"><span class="function">                                  <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;pair : attrs) &#123;</span><br><span class="line">    <span class="type">const</span> std::string &amp;name = pair.first;</span><br><span class="line">    <span class="comment">// 1.得到pnnx中的Attribute</span></span><br><span class="line">    <span class="type">const</span> pnnx::Attribute &amp;attr = pair.second;</span><br><span class="line">    <span class="keyword">switch</span> (attr.type) &#123;</span><br><span class="line">      <span class="keyword">case</span> <span class="number">1</span>: &#123;</span><br><span class="line">        <span class="comment">// 2. 根据Pnnx的Attribute初始化KuiperInferOperator中的Attribute</span></span><br><span class="line">        std::shared_ptr&lt;RuntimeAttribute&gt; runtime_attribute = std::<span class="built_in">make_shared</span>&lt;RuntimeAttribute&gt;();</span><br><span class="line">        runtime_attribute-&gt;type = RuntimeDataType::kTypeFloat32;</span><br><span class="line">         <span class="comment">// 2.1 赋值权重weight(此处的data是std::vector&lt;uchar&gt;类型)</span></span><br><span class="line">        runtime_attribute-&gt;weight_data = attr.data;</span><br><span class="line">        runtime_attribute-&gt;shape = attr.shape;</span><br><span class="line">        runtime_operator-&gt;attribute.<span class="built_in">insert</span>(&#123;name, runtime_attribute&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">default</span> : &#123;</span><br><span class="line">        <span class="built_in">LOG</span>(FATAL) &lt;&lt; <span class="string">&quot;Unknown attribute type&quot;</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><strong>初始化RuntimeOperator的参数(Param)属性</strong><br><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">RuntimeGraph::InitGraphParams</span><span class="params">(<span class="type">const</span> std::map&lt;std::string, pnnx::Parameter&gt; &amp;params,</span></span></span><br><span class="line"><span class="params"><span class="function">                                   <span class="type">const</span> std::shared_ptr&lt;RuntimeOperator&gt; &amp;runtime_operator)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;pair : params) &#123;</span><br><span class="line">    <span class="type">const</span> std::string &amp;name = pair.first;</span><br><span class="line">    <span class="type">const</span> pnnx::Parameter &amp;parameter = pair.second;</span><br><span class="line">    <span class="type">const</span> <span class="type">int</span> type = parameter.type;</span><br><span class="line">    <span class="comment">// 根据PNNX的Parameter去初始化KuiperInfer::RuntimeOperator中的Parameter</span></span><br><span class="line">    <span class="keyword">switch</span> (type) &#123;</span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterUnknown)</span>: &#123;</span></span><br><span class="line">        RuntimeParameter *runtime_parameter = <span class="keyword">new</span> RuntimeParameter;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">// 在这应该使用派生类RuntimeParameterBool </span></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterBool)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterBool *runtime_parameter = <span class="keyword">new</span> RuntimeParameterBool;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.b;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">// 在这应该使用派生类RuntimeParameterInt</span></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterInt)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterInt *runtime_parameter = <span class="keyword">new</span> RuntimeParameterInt;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.i;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterFloat)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterFloat *runtime_parameter = <span class="keyword">new</span> RuntimeParameterFloat;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.f;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterString)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterString *runtime_parameter = <span class="keyword">new</span> RuntimeParameterString;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.s;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterIntArray)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterIntArray *runtime_parameter = <span class="keyword">new</span> RuntimeParameterIntArray;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.ai;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterFloatArray)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterFloatArray *runtime_parameter = <span class="keyword">new</span> RuntimeParameterFloatArray;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.af;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="function"><span class="keyword">case</span> <span class="title">int</span><span class="params">(RuntimeParameterType::kParameterStringArray)</span>: &#123;</span></span><br><span class="line">        RuntimeParameterStringArray *runtime_parameter = <span class="keyword">new</span> RuntimeParameterStringArray;</span><br><span class="line">        runtime_parameter-&gt;value = parameter.as;</span><br><span class="line">        runtime_operator-&gt;params.<span class="built_in">insert</span>(&#123;name, runtime_parameter&#125;);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">default</span>: &#123;</span><br><span class="line">        <span class="built_in">LOG</span>(FATAL) &lt;&lt; <span class="string">&quot;Unknown parameter type&quot;</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://kilogrand.gitee.io">kiloGrand</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://kilogrand.gitee.io/2023/03/17/kuiper_infer-L7/">https://kilogrand.gitee.io/2023/03/17/kuiper_infer-L7/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://kilogrand.gitee.io" target="_blank">kiloGrand</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/kuiper-infer/">kuiper_infer</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/03/17/kuiper_infer-L6/"><img class="prev-cover" src="/img/coding.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">自制深度学习框架--MaxPooling</div></div></a></div><div class="next-post pull-right"><a href="/2023/03/18/kuiper_infer-L8/"><img class="next-cover" src="/img/coding.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">自制深度学习框架--计算图中表达式的解析</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/03/20/kuiper_infer-L10/" title="自制深度学习框架--Im2Col原理与卷积层的实现"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-20</div><div class="title">自制深度学习框架--Im2Col原理与卷积层的实现</div></div></a></div><div><a href="/2023/03/21/kuiper_infer-L11/" title="自制深度学习框架--再探Tensor类并构建计算图的图关系"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-21</div><div class="title">自制深度学习框架--再探Tensor类并构建计算图的图关系</div></div></a></div><div><a href="/2023/03/24/kuiper_infer-L14/" title="自制深度学习框架--实现Yolov5的推理"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-24</div><div class="title">自制深度学习框架--实现Yolov5的推理</div></div></a></div><div><a href="/2023/03/22/kuiper_infer-L12/" title="自制深度学习框架--算子的执行流程"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-22</div><div class="title">自制深度学习框架--算子的执行流程</div></div></a></div><div><a href="/2023/03/23/kuiper_infer-L13/" title="自制深度学习框架--实现ResNet网络的推理"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-23</div><div class="title">自制深度学习框架--实现ResNet网络的推理</div></div></a></div><div><a href="/2023/03/14/kuiper_infer-L3/" title="自制深度学习框架--导入数据"><img class="cover" src="/img/coding.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-14</div><div class="title">自制深度学习框架--导入数据</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/profile.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">kiloGrand</div><div class="author-info__description">coder && data-science researcher</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">46</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/kiloGrand/"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#PNNX"><span class="toc-number">1.</span> <span class="toc-text">PNNX</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PNNX%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%AE%9A%E4%B9%89"><span class="toc-number">2.</span> <span class="toc-text">PNNX的格式定义</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E6%88%91%E4%BB%AC%E8%87%AA%E5%B7%B1%E7%9A%84Operator%E5%92%8COperand"><span class="toc-number">3.</span> <span class="toc-text">定义我们自己的Operator和Operand</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%8EPNNX%E8%AE%A1%E7%AE%97%E5%9B%BE%E5%88%B0KuiperInfer%E8%AE%A1%E7%AE%97%E5%9B%BE%E7%9A%84%E8%BF%87%E7%A8%8B"><span class="toc-number">4.</span> <span class="toc-text">从PNNX计算图到KuiperInfer计算图的过程</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/24/kuiper_infer-L14/" title="自制深度学习框架--实现Yolov5的推理">自制深度学习框架--实现Yolov5的推理</a><time datetime="2023-03-24T12:00:00.000Z" title="发表于 2023-03-24 20:00:00">2023-03-24</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/23/kuiper_infer-L13/" title="自制深度学习框架--实现ResNet网络的推理">自制深度学习框架--实现ResNet网络的推理</a><time datetime="2023-03-23T12:00:00.000Z" title="发表于 2023-03-23 20:00:00">2023-03-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/22/kuiper_infer-L12/" title="自制深度学习框架--算子的执行流程">自制深度学习框架--算子的执行流程</a><time datetime="2023-03-22T12:00:00.000Z" title="发表于 2023-03-22 20:00:00">2023-03-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/21/kuiper_infer-L11/" title="自制深度学习框架--再探Tensor类并构建计算图的图关系">自制深度学习框架--再探Tensor类并构建计算图的图关系</a><time datetime="2023-03-21T12:00:00.000Z" title="发表于 2023-03-21 20:00:00">2023-03-21</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/20/kuiper_infer-L10/" title="自制深度学习框架--Im2Col原理与卷积层的实现">自制深度学习框架--Im2Col原理与卷积层的实现</a><time datetime="2023-03-20T12:00:00.000Z" title="发表于 2023-03-20 20:00:00">2023-03-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By kiloGrand</div><div class="footer_custom_text">Hi, welcome to my blog!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.2
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container:not\([display]\)').forEach(node => {
            const target = node.parentNode
            if (target.nodeName.toLowerCase() === 'li') {
              target.parentNode.classList.add('has-jax')
            } else {
              target.classList.add('has-jax')
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>